2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCER_GROUPCOMPONENTHANDLER_JUCEHEADER__
27 #define __JUCER_GROUPCOMPONENTHANDLER_JUCEHEADER__
30 //==============================================================================
33 class GroupComponentHandler
: public ComponentTypeHandler
36 //==============================================================================
37 GroupComponentHandler()
38 : ComponentTypeHandler ("Group Box", "GroupComponent", typeid (GroupComponent
), 200, 150)
40 registerColour (GroupComponent::outlineColourId
, "outline", "outlinecol");
41 registerColour (GroupComponent::textColourId
, "text", "textcol");
44 //==============================================================================
45 Component
* createNewComponent (JucerDocument
*)
47 return new GroupComponent ("new group", "group");
50 XmlElement
* createXmlFor (Component
* comp
, const ComponentLayout
* layout
)
52 GroupComponent
* const g
= (GroupComponent
*) comp
;
54 XmlElement
* e
= ComponentTypeHandler::createXmlFor (comp
, layout
);
55 e
->setAttribute ("title", g
->getText());
57 GroupComponent
defaultComp (String::empty
, String::empty
);
59 if (g
->getTextLabelPosition().getFlags() != defaultComp
.getTextLabelPosition().getFlags())
60 e
->setAttribute ("textpos", g
->getTextLabelPosition().getFlags());
65 bool restoreFromXml (const XmlElement
& xml
, Component
* comp
, const ComponentLayout
* layout
)
67 GroupComponent
* const g
= (GroupComponent
*) comp
;
69 if (! ComponentTypeHandler::restoreFromXml (xml
, comp
, layout
))
72 g
->setText (xml
.getStringAttribute ("title", g
->getText()));
73 g
->setTextLabelPosition (Justification (xml
.getIntAttribute ("textpos", g
->getTextLabelPosition().getFlags())));
78 const String
getCreationParameters (Component
* component
)
80 GroupComponent
* g
= dynamic_cast <GroupComponent
*> (component
);
82 return quotedString (component
->getName())
84 + quotedString (g
->getText());
87 void fillInCreationCode (GeneratedCode
& code
, Component
* component
, const String
& memberVariableName
)
89 ComponentTypeHandler::fillInCreationCode (code
, component
, memberVariableName
);
91 GroupComponent
* const g
= dynamic_cast <GroupComponent
*> (component
);
95 GroupComponent
defaultComp (String::empty
, String::empty
);
97 if (g
->getTextLabelPosition().getFlags() != defaultComp
.getTextLabelPosition().getFlags())
99 s
<< memberVariableName
<< "->setTextLabelPosition ("
100 << justificationToCode (g
->getTextLabelPosition())
104 s
<< getColourIntialisationCode (component
, memberVariableName
)
107 code
.constructorCode
+= s
;
110 void getEditableProperties (Component
* component
, JucerDocument
& document
, Array
<PropertyComponent
*>& properties
)
112 ComponentTypeHandler::getEditableProperties (component
, document
, properties
);
114 properties
.add (new GroupTitleProperty ((GroupComponent
*) component
, document
));
115 properties
.add (new GroupJustificationProperty ((GroupComponent
*) component
, document
));
117 addColourProperties (component
, document
, properties
);
121 //==============================================================================
122 class GroupTitleProperty
: public ComponentTextProperty
<GroupComponent
>
125 GroupTitleProperty (GroupComponent
* component_
, JucerDocument
& document_
)
126 : ComponentTextProperty
<GroupComponent
> ("text", 200, false, component_
, document_
)
129 //==============================================================================
130 void setText (const String
& newText
)
132 document
.perform (new GroupTitleChangeAction (component
, *document
.getComponentLayout(), newText
),
133 "Change group title");
136 const String
getText() const
138 return component
->getText();
142 class GroupTitleChangeAction
: public ComponentUndoableAction
<GroupComponent
>
145 GroupTitleChangeAction (GroupComponent
* const comp
, ComponentLayout
& layout
, const String
& newName_
)
146 : ComponentUndoableAction
<GroupComponent
> (comp
, layout
),
149 oldName
= comp
->getText();
155 getComponent()->setText (newName
);
163 getComponent()->setText (oldName
);
168 String newName
, oldName
;
172 //==============================================================================
173 class GroupJustificationProperty
: public JustificationProperty
,
174 public ChangeListener
177 GroupJustificationProperty (GroupComponent
* const group_
, JucerDocument
& document_
)
178 : JustificationProperty ("layout", true),
182 document
.addChangeListener (this);
185 ~GroupJustificationProperty()
187 document
.removeChangeListener (this);
190 void setJustification (const Justification
& newJustification
)
192 document
.perform (new GroupJustifyChangeAction (group
, *document
.getComponentLayout(), newJustification
),
193 "Change text label position");
196 const Justification
getJustification() const
198 return group
->getTextLabelPosition();
201 void changeListenerCallback (ChangeBroadcaster
*) { refresh(); }
204 GroupComponent
* const group
;
205 JucerDocument
& document
;
207 class GroupJustifyChangeAction
: public ComponentUndoableAction
<GroupComponent
>
210 GroupJustifyChangeAction (GroupComponent
* const comp
, ComponentLayout
& layout
, const Justification
& newState_
)
211 : ComponentUndoableAction
<GroupComponent
> (comp
, layout
),
212 newState (newState_
),
213 oldState (comp
->getTextLabelPosition())
220 getComponent()->setTextLabelPosition (newState
);
228 getComponent()->setTextLabelPosition (oldState
);
233 Justification newState
, oldState
;
239 #endif // __JUCER_GROUPCOMPONENTHANDLER_JUCEHEADER__